package com.itheima.responsedemo;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/pay")
public class PayServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
         //我们应该获取用户名和密码完成扣款 假设用户名密码没问题
        String username = request.getParameter("username");
        //用户名密码ok 扣款成功的话  是不是应该更新订单状态
        System.out.println("更新订单状，订单已经支付");

        //如果支付成功  是不是应该完成跳转？

        response.setContentType("text/html;charset=utf-8");
        //跳转的时候 会给一些提示 比如 支付成功 3秒之后进行跳转
        response.getWriter().write(username+",您已经支付成功，3秒之后进行跳转");

        //怎么完成跳转呢 ？而且是3秒之后 跳转呢
        //需要设置一个响应头
        response.setHeader("refresh","3;url='success.html'");
    }
}
